import { apiOrderStatusCount, apiSelectdictionaryDataByTypeId } from 'js/api'

export default {
  state: {
    oOrderStatusCount: {}, // 所有订单状态数量
    curStatus: -1, // 当前状态
    delOrderList: []
  },
  getters: {
    oOrderStatusCount: state => state.oOrderStatusCount,
    curStatus: state => state.curStatus,
    delOrderList: state => state.delOrderList
  },
  actions: {
    // 获取我的订单各状态下的数量
    fetchOrderStatusCount({ state }, token) {
      apiOrderStatusCount(token).then(data => {
        state.oOrderStatusCount = data
      })
    },

    // 获取数据字典
    fetchSelectdictionaryDataByTypeId({ state }) {
      // 请求接口
      apiSelectdictionaryDataByTypeId().then(data => {
        state.delOrderList = []
        if (!data.DictionaryDataList || data.DictionaryDataList.length == 0) {
          return
        }
        data.DictionaryDataList.forEach(item => {
          state.delOrderList.push({value: item.dataName, label: item.dataName})
        })
      })
    }
  },
  mutations: {
    // tab订单状态切换
    selectTabOrderStatus(state, payload) {
      state.curStatus = payload
    }
  }
}
